import torch

x = torch.ones(2,2,requires_grad=True)
device = 'cpu'
x = x.to(device)
y = x + 2
print(y.data)
print(y.grad_fn)

z = y * y
print(z.grad_fn)
t = torch.mean(z)
t.backward()
print(x.grad)